home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / screen-resolution-extra / policyui.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  7KB  |  200 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import gtk
  5. import gobject
  6. import sys
  7. import dbus
  8. import logging
  9. import ScreenResolution
  10. from ScreenResolution import ui
  11. SERVICE_NAME = 'com.ubuntu.ScreenResolution.Mechanism'
  12. OBJECT_PATH = '/'
  13. INTERFACE_NAME = 'com.ubuntu.ScreenResolution.Mechanism'
  14. usage = 'python policyui.py 1024x768'
  15. import os
  16. import sys
  17. from subprocess import Popen, PIPE
  18. import XKit
  19. from XKit import xutils, xorgparser
  20. clean = False
  21.  
  22. def checkVirtual(virtres):
  23.     """See if it's necessary to set the virtual resolution"""
  24.     source = '/etc/X11/xorg.conf'
  25.     
  26.     try:
  27.         a = xutils.XUtils(source)
  28.     except (IOError, XKit.xorgparser.ParseException):
  29.         return False
  30.  
  31.     if len(a.globaldict['Screen']) > 0:
  32.         res = None
  33.         for screen in a.globaldict['Screen']:
  34.             
  35.             try:
  36.                 res = a.getValue('SubSection', 'virtual', 0, identifier = 'Display', sect = 'Screen', reference = None)
  37.                 if res:
  38.                     if 'x' in res.lower():
  39.                         res = res.lower().split('x')
  40.                     elif ' ' in res.lower().strip():
  41.                         res = res.lower().split(' ')
  42.                         res = filter((lambda x: x != ''), res)
  43.                         if len(res) == 2 and int(virtres[0]) <= int(res[0]) and int(virtres[1]) <= int(res[1]):
  44.                             return True
  45.                     
  46.             continue
  47.             except (XKit.xorgparser.SectionException, XKit.xorgparser.OptionException, AttributeError):
  48.                 continue
  49.             
  50.  
  51.         
  52.     
  53.     return False
  54.  
  55.  
  56. def get_xkit_service(widget = None):
  57.     '''
  58.     returns a dbus interface to the screenresolution mechanism
  59.     '''
  60.     service_object = dbus.SystemBus().get_object(SERVICE_NAME, OBJECT_PATH)
  61.     service = dbus.Interface(service_object, INTERFACE_NAME)
  62.     return service
  63.  
  64.  
  65. def gui_dialog(message, parent_dialog, message_type = None, widget = None, page = 0, broken_widget = None):
  66.     '''
  67.     Displays an error dialog.
  68.     '''
  69.     if message_type == 'error':
  70.         message_type = gtk.MESSAGE_ERROR
  71.         logging.error(message)
  72.     elif message_type == 'info':
  73.         message_type = gtk.MESSAGE_INFO
  74.         logging.info(message)
  75.     
  76.     dialog = gtk.MessageDialog(parent_dialog, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, message_type, gtk.BUTTONS_OK, message)
  77.     translation = ui.AbstractUI()
  78.     dialog.set_title(translation.string_title)
  79.     if widget != None:
  80.         if isinstance(widget, gtk.CList):
  81.             widget.select_row(page, 0)
  82.         elif isinstance(widget, gtk.Notebook):
  83.             widget.set_current_page(page)
  84.         
  85.     
  86.     if broken_widget != None:
  87.         broken_widget.grab_focus()
  88.         if isinstance(broken_widget, gtk.Entry):
  89.             broken_widget.select_region(0, -1)
  90.         
  91.     
  92.     if parent_dialog:
  93.         dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
  94.         dialog.set_transient_for(parent_dialog)
  95.     else:
  96.         dialog.set_position(gtk.WIN_POS_CENTER)
  97.     ret = dialog.run()
  98.     dialog.destroy()
  99.     return ret
  100.  
  101.  
  102. class BootWindow:
  103.     optimal_virtual_resolution = [
  104.         '2048',
  105.         '2048']
  106.     
  107.     def __init__(self, resolution):
  108.         translation = ui.AbstractUI()
  109.         self.permission_text = translation.string_permission_text
  110.         self.dbus_cant_connect = translation.string_dbus_cant_connect
  111.         self.operation_complete = translation.string_operation_complete
  112.         self.cant_apply_settings = translation.string_cant_apply_settings
  113.         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  114.         self.window.connect('delete_event', self.on_delete_event)
  115.         self.window.connect('destroy', self.on_destroy)
  116.         self.window.set_border_width(20)
  117.         self.window.set_title(translation.string_title)
  118.         self.window.set_position(gtk.WIN_POS_CENTER)
  119.         gtk.window_set_default_icon_from_file('/usr/share/icons/hicolor/16x16/apps/gnome-display-properties.png')
  120.         vbox = gtk.VBox(spacing = 20)
  121.         self.resolution = resolution
  122.         self.label = gtk.Label(self.permission_text)
  123.         self.label.set_line_wrap(True)
  124.         self.label.set_justify(gtk.JUSTIFY_FILL)
  125.         self.button1 = gtk.Button(label = None, stock = 'gtk-yes', use_underline = False)
  126.         self.button1.connect('clicked', self.on_button1_clicked, None)
  127.         self.button1.show()
  128.         self.button2 = gtk.Button(label = None, stock = 'gtk-no', use_underline = False)
  129.         self.button2.connect('clicked', self.on_button2_clicked, None)
  130.         self.button2.show()
  131.         buttonbox = gtk.HButtonBox()
  132.         buttonbox.set_layout(gtk.BUTTONBOX_END)
  133.         buttonbox.set_spacing(10)
  134.         buttonbox.pack_start(self.button2)
  135.         buttonbox.pack_start(self.button1)
  136.         buttonbox.show()
  137.         vbox.pack_start(self.label)
  138.         vbox.pack_start(buttonbox)
  139.         self.window.add(vbox)
  140.         self.label.show()
  141.         vbox.show()
  142.  
  143.     
  144.     def on_button1_clicked(self, widget, data = None):
  145.         global clean
  146.         self.window.hide()
  147.         self.conf = get_xkit_service()
  148.         if not self.conf:
  149.             sys.exit(1)
  150.         
  151.         if int(self.resolution[0]) < int(self.optimal_virtual_resolution[0]) and int(self.resolution[1]) < int(self.optimal_virtual_resolution[1]):
  152.             self.resolution = self.optimal_virtual_resolution
  153.         
  154.         status = self.conf.setVirtual(self.resolution)
  155.         if status == True:
  156.             clean = True
  157.             gtk.main_quit()
  158.         else:
  159.             gtk.main_quit()
  160.  
  161.     
  162.     def on_button2_clicked(self, widget, data = None):
  163.         self.window.hide()
  164.         gtk.main_quit()
  165.  
  166.     
  167.     def on_delete_event(self, widget, event, data = None):
  168.         return False
  169.  
  170.     
  171.     def on_destroy(self, widget, data = None):
  172.         gtk.main_quit()
  173.  
  174.     
  175.     def show(self):
  176.         self.window.show()
  177.  
  178.  
  179. if __name__ == '__main__':
  180.     if len(sys.argv) > 1:
  181.         for param in sys.argv[1:]:
  182.             if 'x' not in param:
  183.                 sys.exit(0)
  184.                 continue
  185.         
  186.     else:
  187.         sys.exit(0)
  188.     res = sys.argv[1]
  189.     res = res.strip().split('x')
  190.     if checkVirtual(res):
  191.         sys.exit(0)
  192.     
  193.     window = BootWindow(res)
  194.     window.show()
  195.     gtk.main()
  196.     if not clean:
  197.         sys.exit(1)
  198.     
  199.  
  200.